package utils

import (
	"bytes"
	"encoding/binary"
	"encoding/json"
	"github.com/techoner/gophp"
)

type Converter struct {

}

func (c *Converter) MapToJson(param map[string]interface{}) string{
	dataType , _ := json.Marshal(param)
	dataString := string(dataType)
	return dataString
}

func (c *Converter) IntToBytes(n int) []byte {
	x := int32(n)
	bytesBuffer := bytes.NewBuffer([]byte{})
	binary.Write(bytesBuffer, binary.BigEndian, x)
	return bytesBuffer.Bytes()
}

func (c *Converter) BytesToInt(b []byte) int {
	bytesBuffer := bytes.NewBuffer(b)

	var x int32
	binary.Read(bytesBuffer, binary.BigEndian, &x)

	return int(x)
}

func (c *Converter) Serialize(data map[string]interface{}) string {
	jsonByte, _ := gophp.Serialize(data)
	return string(jsonByte)
}
func (c *Converter) UnSerialize(data string) interface{}{
	out, _ := gophp.Unserialize([]byte(data))
	return  out
}